import { getDataByCode } from '@/components/common/PateoForm/utils/helper';
import { getDicByKey } from '@/support/common';
import { LeftSquareFilled, PlusOutlined } from '@ant-design/icons';
import { Button, Card, Divider, Form, message, Popconfirm, Select } from 'antd';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';
import moment from 'moment';
import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import PateoSearchForm from '../../../components/common/PateoSearchForm';
import PateoTable from '../../../components/common/PateoTable';
import Ellipsis from '../../../components/Ellipsis';
import IPDADetailModal from '../../../components/ipda/ipdaDetailModal';
import TboxDetailModal from '../../../components/Tbox/tboxDetailModel';
import PageHeaderLayout from '../../../layouts/PageHeaderLayout';
import VehicleActiveModal from './activeModal';
import VehicleBatchActiveModal from './batchActiveModal';
import VehicleBindingModel from './bindingModel';
import GroupActiveModal from './groupActiveModal';
import styles from './TableList.less';
import router from 'umi/router';

//分割线
let page = '';
const FormItem = Form.Item;
const { Option } = Select;
let typeMap = new Map();
let enrollMap = new Map();
let realMap = new Map();

const enrollStatusList2 = [
  { dataKey: 0, dataValue: '未激活' },
  { dataKey: 1, dataValue: '激活成功' },
  { dataKey: 2, dataValue: '激活失败' },
  { dataKey: 3, dataValue: '解除失败' },
  { dataKey: 4, dataValue: 'CC审核中' },
  { dataKey: 5, dataValue: 'CC审核失败' },
  { dataKey: 6, dataValue: '激活RC中' },
  { dataKey: 7, dataValue: '激活RC失败' },
  { dataKey: 8, dataValue: '解除RC中' },
  { dataKey: 9, dataValue: '解除RC失败' },
];

const enrollStatusList = [
  { dataKey: 0, dataValue: '未激活' },
  { dataKey: 1, dataValue: '激活成功' },
  { dataKey: 2, dataValue: '激活失败' },
  { dataKey: 3, dataValue: '解除失败' },
];

const RealNameStatusList = [
  { dataKey: '0', dataValue: '未实名认证' },
  { dataKey: '1', dataValue: '认证中' },
  { dataKey: '2', dataValue: '实名认证通过' },
  { dataKey: '3', dataValue: '实名认证失败' },
  { dataKey: '4', dataValue: '解除申请中' },
  { dataKey: '5', dataValue: '实名认证解除成功' },
];

const typeAllList = [
  { dataKey: 2, dataValue: '试乘试驾车' },
  { dataKey: 3, dataValue: '展车' },
  { dataKey: 4, dataValue: '内部测试车' },
  { dataKey: 5, dataValue: '媒体车' },
  { dataKey: 6, dataValue: '质检车' },
  // { dataKey: 7, dataValue: '团购车' },
];
const searchAllList = [
  { dataKey: 1, dataValue: '用户车' },
  { dataKey: 2, dataValue: '试乘试驾车' },
  { dataKey: 3, dataValue: '展车' },
  { dataKey: 4, dataValue: '内部测试车' },
  { dataKey: 5, dataValue: '媒体车' },
  { dataKey: 6, dataValue: '质检车' },
  // { dataKey: 7, dataValue: '团购车' },
];
const dealerList = [
  { dataKey: 2, dataValue: '试乘试驾车' },
  { dataKey: 3, dataValue: '展车' },
  // { dataKey: 7, dataValue: '团购车' },
];
const dealerSearchList = [
  { dataKey: 1, dataValue: '用户车' },
  { dataKey: 2, dataValue: '试乘试驾车' },
  { dataKey: 3, dataValue: '展车' },
  // { dataKey: 7, dataValue: '团购车' },
];
const batchList = [
  { dataKey: 4, dataValue: '内部测试车' },
  { dataKey: 5, dataValue: '媒体车' },
  { dataKey: 6, dataValue: '质检车' },
];
//S31相关数据
const s31DealerActiveList = [//S31经销商类型车激活类型
  { dataKey: 3, dataValue: '展车' },
];
const s31ActiveList = [//S31车厂类型车激活类型
  { dataKey: 6, dataValue: '质检车' },
  { dataKey: 9, dataValue: '试制车' },
];
const s31SearchList = [//条件查询-- 所有类型
  { dataKey: 1, dataValue: '用户车' },
  { dataKey: 3, dataValue: '展车' },
  { dataKey: 6, dataValue: '质检车' },
  { dataKey: 9, dataValue: '试制车' },
];
const s31DealerSearchList = [//条件查询--经销商只有用户车及展车类型
  { dataKey: 1, dataValue: '用户车' },
  { dataKey: 3, dataValue: '展车' },
];
const s31TypeAllList = [ //总激活类型
  { dataKey: 3, dataValue: '展车' },
  { dataKey: 6, dataValue: '质检车' },
  { dataKey: 9, dataValue: '试制车' },
];
// @connect(state => ({
//   menu: state.menu,
//   extendForm: state.extendForm,
// }))
// @connect()
// @Form.create()
class VehicleList extends PureComponent {
  static contextTypes = {
    authButton: PropTypes.array,
    dicData: PropTypes.any,
  };

  fromRef = React.createRef();
  state = {
    redisData: {},

    // bindingEditVisible: false,
    tboxDetailVisible: false,
    vinDetailVisible: false,
    simDetailVisible: false,
    ipdaDetailVisible: false,
    tboxDetailModelData: {},
    vinDetailModelData: {},
    simDetailModelData: {},
    ipdaDetailModelData: {},
    // bindingEditModelData: {},
    formValues: {},
    dealerOptions: '',
    factoryOptions: '',
    factoryVisible: false,// 搜索栏默认不显示“车厂”，只有运维账号显示
    dealerVisible: true, //搜索栏默认展示“经销商”，“网联类型”，经销商账号不显示
    colorList: [],
    // typeOptions: '',
    typeOptions: [],
    activeVisible: false,
    data: '',
    title: '激活车辆',
    label: '工作联络单',
    activeBatchVisible: false,
    detailDisable: false,
    inputVisible: { display: 'none' },
    dateVisible: { display: 'none' },
    phoneVisible: { display: 'none' },
    type: '',
    typeSearchOptions: '',
    templateFileUrl: '',
    typeBatchOptions: '',
    activeDealerOptions: '',
    activeDealerVisible: { display: 'none' },
    dealerActiveTypeOptions: '',
    uploadUrlVisible: { display: 'none' },
    urlsVisible: { display: 'none' },
    activeFileUrl: '',
    modelVisible: { display: 'none' },
    activeTypeDisabled: false,
    reActiveFlag: false,
    businessLicenseVisible: { display: 'none' },
    codeVisible: { display: 'none' },
    phoneDisable: false,
    qualityUserOptions: '',
    qualityVisible: { display: 'none' },
    declarerVisible: {},
    qualityUserMap: '',
    phoneMap: '',
    remarksDesc: '',
    realNameDisable: false,
    showUploadList: true,
    enrollStatusOptions: [],
    realNameStatusOptions: [],
    groupActiveVisible: false, // 集团企业批量激活
    historyVisible: false, //  历史记录明细
    historyModalData: [],
    bindUserVisible: false, // 绑定页
    bindData: {},
    groupActiveFileUrl: '', // 企业批量激活url
    subDealerVisible: { display: 'none' }, //是否二网车辆
  };
  /**
   * todo   刷新数据是否清空搜索框  绑定/解绑失败原因
   */
  componentWillMount() {
    this.props.dispatch({
      type: 'menu/getMenuData',
    })
    const {menu: { userProfile, dataPermission,permissions}} = this.props;
    console.log('userProfile', userProfile);
    console.log('dataPermission', dataPermission);
    const isS31 = permissions.includes("/deviceManager/vehicle/vehicle-forS31");//是否为S31用户
    // if (orgType) {
    // const { levelCode } = this.props.currentUser;
    // if (levelCode) {
    //   if (levelCode.split('-').length === 2) {//运维条件筛选展示
      //   this.setState({ factoryVisible: {} });
      // }
      if (dataPermission.PERSON && dataPermission.PERSON.length > 0) {
        if(dataPermission.PERSON[0] == '1'){//运维角色
          if(isS31){//s31用户
          this.setState({ factoryVisible: true }); //筛选条件显示
          this.setState({
            typeOptions: s31TypeAllList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
            typeSearchOptions: s31SearchList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
          });
         }else{
          this.setState({ factoryVisible: true }); //筛选条件显示
          this.setState({
            typeOptions: typeAllList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
            typeSearchOptions: searchAllList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
          });
         }
        }
        else if(dataPermission.PERSON[0] == '3'){ //经销商角色
      // if (levelCode.split('-').length === 4) {//经销商
        // if (this.props.currentUser.userName === '总部经销商') {
        //   this.setState({
        //     typeOptions: typeAllList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
        //     typeSearchOptions: searchAllList.map(d => (
        //       <Option key={d.dataKey}>{d.dataValue}</Option>
        //     )),
        //     dealerVisible: { display: 'none' },
        //     detailDisable: true,
        //   });
        // } else {
          if(isS31){
            this.setState({
              typeOptions: s31DealerActiveList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
              typeSearchOptions: s31DealerSearchList.map(d => (
                <Option key={d.dataKey}>{d.dataValue}</Option>
              )),
              dealerVisible: false,
              detailDisable: true,
            });
          }else{
          this.setState({
            typeOptions: dealerList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
            typeSearchOptions: dealerSearchList.map(d => (
              <Option key={d.dataKey}>{d.dataValue}</Option>
            )),
            dealerVisible: false,
            detailDisable: true,
          });
        }
        }else{//非运维非经销商角色
             if(isS31){
              this.setState({
                typeOptions: s31TypeAllList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
                typeSearchOptions: s31SearchList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
              });
             }else{
        this.setState({
          typeOptions: typeAllList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
          typeSearchOptions: searchAllList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
        });
       }
      }
        // }
        
      } else {
        if(isS31){
          this.setState({
            typeOptions: s31TypeAllList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
            typeSearchOptions: s31SearchList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
          });
         }else{
        this.setState({
          typeOptions: typeAllList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
          typeSearchOptions: searchAllList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
        });
       }
      }
    // }
  
    const { dispatch } = this.props;
    if (this.props.location && this.props.location.state) {
      const { query } = this.props.location.state;
      if (query) {
        const { pageObj, values } = query;
        this.setState({ formValues: values });
        dispatch({
          type: 'vehicle/fetch',
          payload: {
            page: pageObj.current - 1,
            size: pageObj.pageSize,
            ...values,
          },
          callback: response => {
            if (response.code && response.code === '500') {
              message.error(response.description);
            }
          },
        });
      } else {
        dispatch({
          type: 'vehicle/fetch',
          callback: response => {
            if (response.code && response.code === '500') {
              message.error(response.description);
            }
          },
        });
      }
    } else {
      dispatch({
        type: 'vehicle/fetch',
        callback: response => {
          if (response.code && response.code === '500') {
            message.error(response.description);
          }
        },
      });
    }

    this.setState({
      enrollStatusOptions: enrollStatusList.map(d => (
        <Option key={d.dataKey}>{d.dataValue}</Option>
      )),
      realNameStatusOptions: RealNameStatusList.map(d => (
        <Option key={d.dataKey}>{d.dataValue}</Option>
      )),
      dealerActiveTypeOptions: isS31 ? s31DealerActiveList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>) : dealerList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
      typeBatchOptions: isS31 ? s31ActiveList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>) : batchList.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
    });

    enrollStatusList.map(d => enrollMap.set(d.dataKey, d.dataValue));
    RealNameStatusList.map(d => realMap.set(d.dataKey, d.dataValue));
    if(isS31){
      s31SearchList.map(d => typeMap.set(d.dataKey, d.dataValue));
      }
    else{
      searchAllList.map(d => typeMap.set(d.dataKey, d.dataValue));
    }
    // this.props.dispatch({
    //   type: 'basedata/findVehicleActiveList',
    //   callback: (response) => {
    //     this.setState({
    //       typeOptions: response.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
    //       typeSearchOptions: response.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
    //     });
    //   },
    // });
    // this.props.dispatch({
    //   type: 'basedata/findVehicleActiveListByDealer',
    //   callback: (response) => {
    //     this.setState({
    //       dealerActiveTypeOptions: response.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
    //     });
    //   },
    // });
    // this.props.dispatch({
    //   type: 'basedata/findVehicleBatchActiveList',
    //   callback: (response) => {
    //     this.setState({
    //       typeBatchOptions: response.map(d => <Option key={d.dataKey}>{d.dataValue}</Option>),
    //     });
    //   },
    // });
    //todo: zn - 批量激活 - 质检人员列表
    this.props.dispatch({
      type: 'qualityUser/findAllQualityUser',
      callback: (response) => {
        let map = new Map();
        let phoneMap =  new Map();
        response.map(d => map.set(d.sid,d.name));
        response.map(d => phoneMap.set(d.sid,d.phone));
        this.setState({
          qualityUserOptions: response.map(d => <Option title={d.name} key={d.sid}>{d.name}</Option>),
          qualityUserMap: map,
          phoneMap,
        });
      },
    });
    dispatch({
      type: 'qualityTest/options',
      payload: { url: '/groupManagement/getOption' },
    });
    dispatch({
      type: 'menu/getMenuData',
    });
  }
  componentDidMount() {
    const {menu: {dataPermission}} = this.props;
    const brandCodes = dataPermission.BRAND ? dataPermission.BRAND : []
    // const { brandCodes } = this.props.currentUser;
    if (this.state.formValues) {
      // console.log(this.fromRef);
      this.fromRef.current.setFieldsValue(this.state.formValues);
    }
    this.props.dispatch({
      type: 'basedata/findDealerByBrand',
      payload: { factory: brandCodes.join(',') },
      callback: response => {
        if (response) {
          this.setState({
            dealerOptions: response.map(d => (
              <Option title={d.name ? d.name : d.code} key={d.code}>
                <Ellipsis length={12} tooltip>
                  {d.name ? d.name : d.code}
                </Ellipsis>
              </Option>
            )),
          });
        } else {
          this.setState({
            dealerOptions: '',
          });
        }
      },
    });

    this.props.dispatch({
      type: 'maintenance/fetchDealer',
      callback: response => {
        this.setState({
          //dealerOptions: response.filter(item => item.code !== '').map(d => <Option title={d.name} key={d.code}><Ellipsis length={12} tooltip>{d.name}</Ellipsis></Option>),
          activeDealerOptions: response
            .filter(item => item.code !== '')
            .map(d => (
              <Option title={d.name} key={d.code}>
                <Ellipsis length={12} tooltip>
                  {d.name}
                </Ellipsis>
              </Option>
            )),
        });
      },
    });
    this.props.dispatch({
      type: 'basedata/findFactoryBrand',
      callback: response => {
        this.setState({
          factoryOptions: response.data.map(d => (
            <Option title={d.dataValue} key={d.dataKey}>
              <Ellipsis length={12} tooltip>
                {d.dataValue}
              </Ellipsis>
            </Option>
          )),
        });
      },
    });

    this.props.dispatch({
      type: 'basedata/redisDataFetch',
      callback: response => {
        if (response) {
          this.setState({ redisData: response });
        }
      },
    });
  }

  onFactorySelect = value => {
    this.fromRef.current.setFieldsValue({ dealerNo: undefined });
    this.setState({
      dealerOptions: [],
    });
    this.props.dispatch({
      type: 'basedata/findDealerByBrand',
      payload: { factory: value },
      callback: response => {
        if (response) {
          this.setState({
            dealerOptions: response.map(d => (
              <Option title={d.name ? d.name : d.code} key={d.code}>
                <Ellipsis length={12} tooltip>
                  {d.name ? d.name : d.code}
                </Ellipsis>
              </Option>
            )),
          });
        } else {
          this.setState({
            dealerOptions: undefined,
          });
        }
      },
    });
  };
  onRef = ref => {
    this.VehicleActiveModalRef = ref;
  };
  onBatchRef = ref => {
    this.VehicleBatchActiveModalRef = ref;
  };
  onGroupRef = ref => {
    this.GroupActiveModalRef = ref;
  };
  handleFormReset = () => {
    const {menu: {dataPermission}} = this.props;
    const brandCodes = dataPermission.BRAND ? dataPermission.BRAND : []
    // const { brandCodes } = this.props.currentUser;
    const { dispatch } = this.props;
    this.state.formValues = {};
    dispatch({
      type: 'vehicle/fetch',
      callback: response => {
        if (response.code && response.code === '500') {
          message.error(response.description);
        }
      },
    });
    this.props.dispatch({
      type: 'basedata/findDealerByBrand',
      payload: { factory: brandCodes.join(',') },
      callback: response => {
        if (response) {
          this.setState({
            dealerOptions: response.map(d => (
              <Option title={d.name ? d.name : d.code} key={d.code}>
                <Ellipsis length={12} tooltip>
                  {d.name ? d.name : d.code}
                </Ellipsis>
              </Option>
            )),
          });
        } else {
          this.setState({
            dealerOptions: '',
          });
        }
      },
    });
  };
  handleEditData = deviceId => {
    const { dispatch } = this.props;
    const obj = {};
    obj.pageObj = page;
    obj.values = this.state.formValues;
    dispatch({
      type: 'ipda/findById',
      payload: deviceId,
      callback: data => {
        dispatch(
          routerRedux.push({
            pathname: '/deviceManager/ipdaEdit',
            query: true,
            state: { data, obj },
          }),
        );
      },
    });
  };
  handleBindingData = record => {
    const obj = record;
    obj.page = page;
    obj.formValues = this.state.formValues;
    this.refs.VehicleBindingModelRef.showModalEdit(obj);
  };

  handleSearch = fieldsValue => {
    this.setState({
      formValues: fieldsValue,
    });
    this.props.dispatch({
      type: 'vehicle/fetch',
      payload: fieldsValue,
      callback: response => {
        if (response.code && response.code === '500') {
          message.error(response.description);
        }
      },
    });
  };
  handleDetailTbox = deviceId => {
    const { dispatch } = this.props;
    dispatch({
      type: 'tbox/fetchtboxdetail',
      payload: deviceId,
      callback: tboxDetail => {
        this.setState({ tboxDetailModelData: tboxDetail.data, tboxDetailVisible: true });
      },
    });
  };

  //保存record信息  点击vin号跳转到 连接平台-车辆信息查询-详情页
  handleDetailVIN = deviceId => {
    // 先获取iccid信息
    this.props.dispatch({
      type: 'vehicle/getIccid',
      payload: deviceId.vin,
      callback: res => {
        if(res.statusCode === '0' && res.data.simProfileVo.iccid){
          deviceId['iccid'] = res.data.simProfileVo.iccid;
        } 
        this.props.dispatch({
          type: 'vehicleInfo/setVehicleInfo',
          payload: {
            ...deviceId,
          },
        }).then(()=>{
          router.push({
            pathname: '/deviceManager/vehicle/vehicleInfoDetail',
            state: { module: '车辆管理' },
          });
        });
      },
    })
    // this.props.dispatch({
    //   type: 'vehicleInfo/setVehicleInfo',
    //   payload: {
    //     ...deviceId,
    //   },
    // });
    // router.push({
    //   pathname: '/deviceManager/vehicle/vehicleInfoDetail',
    //   state: { module: '车辆管理' },
    // });
  };

  // // 点击vin号跳转到vehicleDetail页面
  // handleDetailVIN = (vin, record) => {
  //   const { dispatch } = this.props;
  //   const { formValues } = this.state;
  //   dispatch(
  //     routerRedux.push({
  //       pathname: '/deviceManager/vehicle/vehicleDetail',
  //       rowData: record,
  //       flag: true,
  //       sourceName: '/deviceManager/vehicle',
  //       query: { pageObj: page, values: formValues },
  //     }),
  //   );
  // };

  handleDetailSIM = deviceId => {
    const { dispatch } = this.props;
    dispatch({
      type: 'simCard/findById',
      payload: deviceId,
      callback: simDetail => {
        if (simDetail.status.code === '0') {
          this.setState({ simDetailModelData: simDetail, simDetailVisible: true });
        } else {
          message.error(simDetail.status.description);
        }
      },
    });
  };
  handleDetailIPDA = deviceId => {
    const { dispatch } = this.props;
    dispatch({
      type: 'ipda/findById',
      payload: deviceId,
      callback: ipdaDetail => {
        if (ipdaDetail.statusCode === '0') {
          this.setState({ ipdaDetailModelData: ipdaDetail.data, ipdaDetailVisible: true });
        } else {
          message.error(ipdaDetail.statusMessage);
        }
      },
    });
  };
  handleActive = async record => {
    const {menu: { userProfile,dataPermission}} = this.props;
    const realName = userProfile.accountName;
    const phone = userProfile.userMobile;
    let flag = 'other';
    if (dataPermission.PERSON && dataPermission.PERSON.length > 0) {
      if (dataPermission.PERSON[0] == '3') {
        flag = 'dealer';
      } else {
        flag = 'other';
      }
    }
    // const { levelCode, realName, phone } = this.props.currentUser;
    // if (levelCode) {
    //   if (levelCode.split('-').length === 4) {
    //     flag = 'dealer';
    //   } else {
    //     flag = 'other';
    //   }
    // }
    const { typeBatchOptions, dealerActiveTypeOptions, typeSearchOptions } = this.state;
    this.setState({
      title: '激活车辆',
      label: '工作联络单',
      activeTypeDisabled: false,
      reActiveFlag: false,
    });
    if (record.status === 2) {
      //车辆状态为车厂，激活类型选择测试、媒体、质检
      await this.setState({
        activeVisible: true,
        typeOptions: typeBatchOptions,
        activeDealerVisible: { display: 'none' },
      });
      const {
        vehicle: {
          list: { isQuality },
        },
      } = this.props;
      if (isQuality === '0') {
        //质检角色
        this.VehicleActiveModalRef.refs.form.setFieldsValue({
          vin: record.vin,
          activeType: '6',
          expiryDate: moment().add(1, 'days'),
        });
        this.setState({
          uploadUrlVisible: { display: 'none' },
          activeTypeDisabled: true,
          dateVisible: {},
          qualityVisible: {},
          declarerVisible: { display: 'none' },
        });
      } else {
        this.VehicleActiveModalRef.refs.form.setFieldsValue({
          declarerOther: realName,
          phone: phone,
          vin: record.vin,
        });
        //非质检角色
        this.VehicleActiveModalRef.setPhone(phone);
      }
    } else {//车辆数据非车厂
        this.setState({
          typeOptions: dealerActiveTypeOptions,
        });
      // if (this.props.currentUser.userName === '总部经销商') {//当前无总部经销商概念
      //   this.setState({
      //     typeOptions: typeSearchOptions,
      //   });
      // } else {
      //   this.setState({
      //     typeOptions: dealerActiveTypeOptions,
      //   });
      // }
      //车辆状态为经销商，激活类型选择、试乘试驾、展车（用户车不可激活）
      if (flag === 'dealer') {//区分当前登录用户是经销商还是其他用户，经销商用户数据只存在当前经销商的数据，不展示该车是属于哪个经销商tag,并自动填写当前经销商用户的姓名和手机号
        await this.setState({
          activeVisible: true,
          activeDealerVisible: { display: 'none' },
        });
        this.VehicleActiveModalRef.refs.form.setFieldsValue({
          declarerOther: realName,
          phone: phone,
          vin: record.vin,
        });
        this.VehicleActiveModalRef.setPhone(phone);
      } else {
        await this.setState({
          activeVisible: true,
          activeDealerVisible: {},
        });
        this.VehicleActiveModalRef.refs.form.setFieldsValue({
          vin: record.vin,
          orgNo: record.dealerId,
        });
        this.VehicleActiveModalRef.setPhone(phone);
      }
    }
    this.props.dispatch({
      type: 'basedata/fetchTemplate',
      payload: { templateCode: 'dfpvMemo' },
      callback: res => {
        this.setState({ activeFileUrl: res.data ? res.data.templateUrl : '' });
      },
    });
  };

  handleBatchActive = () => {
    const { currentUser, dispatch } = this.props;
    this.setState({ activeBatchVisible: true });
    dispatch({
      type: 'basedata/fetchTemplate',
      payload: { templateCode: 'vehicleBatchActive' },
      callback: res => {
        this.setState({ templateFileUrl: res.data ? res.data.templateUrl : '' });
      },
    });
  };
  handleGroupActive = () => {
    this.setState({ groupActiveVisible: true });
    this.props.dispatch({
      type: 'basedata/fetchTemplate',
      payload: { templateCode: 'groupBatchActive' },
      callback: res => {
        this.setState({ groupActiveFileUrl: res.data ? res.data.templateUrl : '' });
      },
    });
  };
  handleGroupClose = () => {
    this.setState({ groupActiveVisible: false, groupActiveFileUrl: '' });
  };
  handleBingUser = record => {
    this.setState({ bindUserVisible: true, bindData: record });
  };
  handleBingUserClose = () => {
    this.setState({ bindUserVisible: false, bindData: {} });
  };
  handleUntying = record => {
    const formData = [];
    formData.groupId = record.groupId;
    formData.vin = record.vin;
    this.props.dispatch({
      type: 'qualityTest/fetch',
      payload: { url: '/groupManagement/unbind', ...formData },
      callback: response => {
        response.statusCode === '0' ? message.success('解绑成功') : message.error('解绑失败');
        this.props.dispatch({
          type: 'vehicle/fetch',
          payload: {
            page: 0,
            size: 10,
          },
        });
      },
    });
    this.props.form.resetFields();
  };

  handleReActive = record => {
    let str = '';
    if (record.enrollStatus === 5) {
      str = `CC审核失败原因：${record.remarks ? record.remarks : ''}`;
      this.setState({
        realNameDisable: false,
        showUploadList: true,
      });
    } else {
      str = `实名认证失败原因：${record.remarks ? record.remarks : ''}`;
      this.setState({
        activeTypeDisabled: true,
        // realNameDisable: true,
        phoneDisable: true,
        showUploadList: true,
        // showUploadList: {showPreviewIcon: true, showRemoveIcon: false},
      });
    }
    const { dealerActiveTypeOptions } = this.state;
    const typeOptions =
      record.enrollStatus === 5
        ? dealerActiveTypeOptions.filter(item => item.key !== '3')
        : dealerActiveTypeOptions;
    this.setState({
      reActiveFlag: true,
      typeOptions,
      remarksDesc: str,
    });
    const { dispatch } = this.props;
    dispatch({
      type: 'basedata/fetchTemplate',
      payload: { templateCode: 'dfpvMemo' },
      callback: res => {
        this.setState({ activeFileUrl: res.data ? res.data.templateUrl : '' });
      },
    });
    dispatch({
      type: 'vehicle/findVehicleApply',
      payload: record.vin,
      callback: response => {
        const {menu: { userProfile, dataPermission}} = this.props;
        // const { levelCode } = this.props.currentUser;
        if (response.status.code === '200') {
          this.VehicleActiveModalRef.setOriginPhone(response.phone);
          // if (response.activeType.toString() === '1') {
          //   this.setState({
          //     phoneDisable: true,
          //   });
          // }
          if (record.enrollStatus === 5) {
            this.setState({
              title: '重新提交审核',
            });
          } else {
            this.setState({
              title: '重新提交实名认证',
            });
          }
          this.VehicleActiveModalRef.refs.form.setFieldsValue({
            declarerOther: response.declarer,
            phone: response.phone,
            vin: response.vin,
            activeType: response.activeType.toString(),
            applyId: response.applyId,
            certType: response.certType,
            certNo: response.certNo,
            address: response.address,
            expiryDate: response.expiryDate ? moment(response.expiryDate) : response.expiryDate,
            orgNo: record.dealerId,
            sex: response.sex,
            contactName: response.contactName,
            contactTel: response.contactTel,
          });
          this.setState({
            type: response.activeType.toString(),
          });
          if (response.activeType === 2 || response.activeType === 1) {
            if (dataPermission.PERSON && dataPermission.PERSON.length > 0) {
              if (dataPermission.PERSON[0] == '3') {
                this.setState({
                  activeDealerVisible: { display: 'none' },
                });
              } else {
                this.setState({
                  activeDealerVisible: {},
                });
              }
            }
            // if (levelCode) {
            //   if (levelCode.split('-').length === 4) {
            //     this.setState({
            //       activeDealerVisible: { display: 'none' },
            //     });
            //   } else {
            //     this.setState({
            //       activeDealerVisible: {},
            //     });
            //   }
            // }
            this.setState({
              label: '上传资料',
              activeVisible: true,
              inputVisible: {},
              dateVisible: { display: 'none' },
              phoneVisible: { display: 'none' },
              uploadUrlVisible: { display: 'none' },
              urlsVisible: {},
              modelVisible: { display: 'none' },
              // activeTypeDisabled: true,
            });
            if (response.activeType === 1) {
              this.setState({
                businessLicenseVisible: { display: 'none' },
              });
              const list = [];
              list.push(response.url);
              list.push(response.fullFaceUrl);
              list.push(response.backViewUrl);
              list.push(response.handPhotoUrl);
              this.VehicleActiveModalRef.setData(list);
            } else if (response.activeType === 2) {
              this.setState({
                businessLicenseVisible: {},
              });
              const list = [];
              list.push(response.url);
              list.push(response.fullFaceUrl);
              list.push(response.backViewUrl);
              list.push(response.handPhotoUrl);
              list.push(response.businessLicenseUrl);
              this.VehicleActiveModalRef.setData(list);
            }
          } else {
            if (response.activeType === 3) {
              this.VehicleActiveModalRef.setPhone(response.phone);
              this.setState({
                phoneVisible: {},
                subDealerVisible: {},
              });
              if (response.subDealer !== undefined && response.subDealer === true) {
                this.VehicleActiveModalRef.refs.form.setFieldsValue({
                  subDealer: true,
                  subDealerAddress: response.subDealerAddress,
                });
                this.VehicleActiveModalRef.setStateData({
                  lng: response.subDealerLon,
                  lat: response.subDealerLat,
                  subDealerAddressVisible: { marginBottom: 10, marginTop: -15 },
                });
              }
              if (dataPermission.PERSON && dataPermission.PERSON.length > 0) {
                if (dataPermission.PERSON[0] == '3') {
                  this.setState({
                    activeDealerVisible: { display: 'none' },
                  });
                } else {
                  this.setState({
                    activeDealerVisible: {},
                  });
                }
              }
              // if (levelCode) {
              //   if (levelCode.split('-').length === 4) {
              //     this.setState({
              //       activeDealerVisible: { display: 'none' },
              //     });
              //   } else {
              //     this.setState({
              //       activeDealerVisible: {},
              //     });
              //   }
              // }
            }
            this.setState({
              label: '工作联络单',
              activeVisible: true,
              inputVisible: { display: 'none' },
              dateVisible: {},
              uploadUrlVisible: {},
              urlsVisible: { display: 'none' },
              businessLicenseVisible: { display: 'none' },
              modelVisible: {},
              // activeTypeDisabled: true,
            });
            const list = [];
            list.push(response.url);
            this.VehicleActiveModalRef.setData(list);
          }
        } else {
          message.error(response.status.description);
        }
      },
    });
  };

  handelSelect = value => {
    const {menu: { userProfile , dataPermission}} = this.props;
    const realName = userProfile.accountName;
    const phone = userProfile.userMobile;
    let flag = 'other';
    if (dataPermission.PERSON && dataPermission.PERSON.length > 0) {
      if (dataPermission.PERSON[0] == '3') {
        flag = 'dealer';
      } else {
        flag = 'other';
      }
    }
    // let flag = 'other';
    // const { levelCode, realName, phone } = this.props.currentUser;
    // if (levelCode) {
    //   if (levelCode.split('-').length === 4) {
    //     flag = 'dealer';
    //   } else {
    //     flag = 'other';
    //   }
    // }
    this.VehicleActiveModalRef.setStateData({
      subDealerAddressVisible: { display: 'none' },
      lng: '',
      lat: '',
    });
    this.setState({
      subDealerVisible: { display: 'none' },
      declarerVisible: {},
      qualityVisible: { display: 'none' },
      type: value,
      phoneDisable: false,
    });
    this.VehicleActiveModalRef.refs.form.resetFields(['expiryDate']);
    if (value === '2' || value === '1') {
      this.setState({
        codeVisible: {},
      });
      this.VehicleActiveModalRef.refs.form.setFieldsValue({
        sex: '0',
      });
      // const sexRadio = getDicByCode(this.context.dicData, 'activeSex');
      // if (sexRadio && sexRadio.length>0) {
      //   sexRadio.sort((a, b) => a.sort - b.sort);
      //   this.VehicleActiveModalRef.refs.form.setFieldsValue({
      //     sex: sexRadio[0].key,
      //   });
      // }
      if (value === '2') {
        this.setState({
          businessLicenseVisible: {},
        });
      } else {
        this.setState({
          businessLicenseVisible: { display: 'none' },
        });
      }
      this.setState({
        label: '上传资料',
        inputVisible: {},
        dateVisible: { display: 'none' },
        phoneVisible: { display: 'none' },
        uploadUrlVisible: { display: 'none' },
        urlsVisible: {},
        modelVisible: { display: 'none' },
      });
      if (flag === 'dealer') {
        if (value === '1') {
          this.VehicleActiveModalRef.refs.form.resetFields(['declarerOther', 'phone']);
          this.VehicleActiveModalRef.resetPhone();
        } else {
          this.VehicleActiveModalRef.refs.form.setFieldsValue({
            declarerOther: realName,
            phone: phone,
          });
          this.VehicleActiveModalRef.setPhone(phone);
        }
      } else {
        this.VehicleActiveModalRef.refs.form.resetFields(['declarerOther', 'phone']);
        this.VehicleActiveModalRef.resetPhone();
      }
    } else {
      this.VehicleActiveModalRef.refs.form.resetFields(['sex']);
      if (value === '3') {
        this.setState({
          phoneVisible: {},
          modelVisible: { display: 'none' },
          codeVisible: {},
          uploadUrlVisible: { display: 'none' },
          subDealerVisible: {},
        });
        this.VehicleActiveModalRef.refs.form.setFieldsValue({
          expiryDate: moment().add(30, 'days'),
          subDealer: true,
        });
        this.VehicleActiveModalRef.setStateData({
          subDealerAddressVisible: { marginBottom: 10, marginTop: -15 },
        });
        if (flag === 'dealer') {
          this.VehicleActiveModalRef.refs.form.setFieldsValue({
            declarerOther: realName,
            phone: phone,
          });
          this.VehicleActiveModalRef.setPhone(phone);
        } else {
          this.VehicleActiveModalRef.refs.form.resetFields(['declarerOther', 'phone']);
          this.VehicleActiveModalRef.resetPhone();
        }
      } else {
        if (value === '6') {
          this.setState({
            uploadUrlVisible: { display: 'none' },
            qualityVisible: {},
            declarerVisible: { display: 'none' },
            phoneDisable: true,
          });
          this.VehicleActiveModalRef.refs.form.setFieldsValue({
            expiryDate: moment().add(1, 'days'),
          });
          this.VehicleActiveModalRef.refs.form.resetFields([
            'declarerOther',
            'phone',
            'declarerQuality',
          ]);
        } else {
          this.setState({
            uploadUrlVisible: {},
          });
          this.VehicleActiveModalRef.refs.form.setFieldsValue({
            declarerOther: realName,
            phone: phone,
          });
          this.VehicleActiveModalRef.setPhone(phone);
        }
        this.setState({
          modelVisible: { display: 'none' },
          codeVisible: { display: 'none' },
        });
      }
      this.setState({
        label: '工作联络单',
        inputVisible: { display: 'none' },
        dateVisible: {},
        urlsVisible: { display: 'none' },
        businessLicenseVisible: { display: 'none' },
        modelVisible: { display: 'none' },
        uploadUrlVisible: { display: 'none' },
      });
    }
    this.VehicleActiveModalRef.handleDel();
    this.VehicleActiveModalRef.refs.form.resetFields([
      'certNo',
      'certType',
      'address',
      'url1',
      'url2',
      'fullFaceUrl',
      'backViewUrl',
      'handPhotoUrl',
      'businessLicenseUrl',
      'captcha',
      'contactName',
      'contactTel',
      'subDealerAddress',
    ]);
  };

  handleSetData = () => {
    this.setState({ data: '' });
  };
  handleCloseActive = () => {
    this.VehicleActiveModalRef.handleDel();
    this.VehicleActiveModalRef.setOriginPhone('');
    this.setState({
      activeVisible: false,
      label: '工作联络单',
      inputVisible: { display: 'none' },
      dateVisible: { display: 'none' },
      phoneVisible: { display: 'none' },
      type: 0,
      activeDealerVisible: { display: 'none' },
      orgNo: '',
      uploadUrlVisible: { display: 'none' },
      urlsVisible: { display: 'none' },
      modelVisible: { display: 'none' },
      activeTypeDisabled: false,
      reActiveFlag: false,
      businessLicenseVisible: { display: 'none' },
      codeVisible: { display: 'none' },
      phoneDisable: false,
      qualityVisible: { display: 'none' },
      declarerVisible: {},
      remarksDesc: '',
      realNameDisable: false,
      showUploadList: true,
      subDealerVisible: { display: 'none' },
    });
  };
  handleCloseBatchActive = () => {
    this.setState({ activeBatchVisible: false });
  };
  handleLogout = vin => {
    const { dispatch } = this.props;
    dispatch({
      type: 'vehicle/vehicleLogout',
      payload: vin,
      callback: response => {
        if (response.code === '200') {
          message.success('注销成功');
          dispatch({
            type: 'vehicle/fetch',
            payload: {
              page: page.current - 1,
              size: page.pageSize,
              ...this.state.formValues,
            },
            callback: response => {
              if (response.code && response.code === '500') {
                message.error(response.description);
              }
            },
          });
        } else {
          if (response.code === '500') {
            message.error(response.description);
          } else {
            message.error('注销失败');
          }
        }
      },
    });
  };

  handleReSendActiveInfo = record => {
    const { dispatch } = this.props;
    const obj = {
      vin: record.vin,
      pdsn: record.pdsn,
      tbox: record.tbox,
    };
    dispatch({
      type: 'vehicle/reSendActiveInfo',
      payload: obj,
      callback: response => {
        if (response.code === '0') {
          message.success('发送成功');
          dispatch({
            type: 'vehicle/fetch',
            payload: {
              page: page.current - 1,
              size: page.pageSize,
              ...this.state.formValues,
            },
            callback: response => {
              if (response.code && response.code === '500') {
                message.error(response.description);
              }
            },
          });
        } else {
          message.error(response.description);
        }
      },
    });
  };

  handleEditVIN = record => {
    const { dispatch } = this.props;
    const obj = {};
    obj.pageObj = page;
    obj.values = this.state.formValues;
    dispatch({
      type: 'vehicle/findProfile',
      payload: record.vin,
      callback: response => {
        if (response.statusCode === '0') {
          if (response.data) {
            const param = response.data;
            param.sid = record.sid;
            dispatch(
              routerRedux.push({
                pathname: '/deviceManager/vehicle/vehicleEdit',
                flag: true,
                state: { data: param, obj },
              }),
            );
          }
        } else {
          message.error(response.statusMessage);
        }
      },
    });
  };
  handleResendActive = (vin, type) => {
    //message.info(type);
    const { dispatch } = this.props;
    const obj = {};
    obj.vin = vin;
    obj.type = type;
    dispatch({
      type: 'vehicle/resendActive',
      payload: obj,
      callback: response => {
        if (response.code === '200') {
          message.success('重新提交成功');
          dispatch({
            type: 'vehicle/fetch',
            payload: {
              page: page.current - 1,
              size: page.pageSize,
              ...this.state.formValues,
            },
            callback: response => {
              if (response.code && response.code === '500') {
                message.error(response.description);
              }
            },
          });
        } else {
          message.error('重新提交失败');
        }
      },
    });
  };

  handleHistory = record => {
    const { dispatch } = this.props;
    dispatch({
      type: 'qualityTest/list',
      payload: { url: '/groupManagement/bingHistory', vin: record.vin },
      callback: response => {
        this.setState({ historyVisible: true, historyModalData: response });
      },
    });
  };
  setCodeVisible = value => {
    this.setState({ codeVisible: value });
  };

  getMessage = type => {
    if (type === 1) {
      return '确定要注销用户车吗?';
    } else if (type === 2) {
      return '确定要注销试乘试驾车吗?';
    }
  };

  //蓝牙钥匙解绑方法  车辆解绑后需要调用
  // handleUntyingWithKey = (vin) =>{
  //   const { dispatch } = this.props;
  //   dispatch({
  //     type: 'alarm/fetch',
  //     payload: { url:'/vehicle/findBlueTooth', vin },
  //     callback: response =>{
  //       if(response.statusCode === '0'){
  //         // 表示存在车主钥匙，进行解绑操作
  //         if(response.data && response.data.owner && response.data.owner.length > 0){
  //           // 存在车主钥匙，进行注销操作
  //           const data = {};
  //           data.deviceId = vin;
  //           data.bleKeyId = response.data.owner[0].id;
  //           dispatch({
  //             type: 'alarm/add',
  //             payload: { url: '/vehicle/deleteBlueTooth', ...data },
  //             callback: response=>{
  //               response.statusCode === "0" ? message.success("指令已下发，您可以查看钥匙操作日志追踪指令状态。") : message.error(response.statusMessage)
  //             }
  //           });
  //         }
  //       } else {
  //         message.error(response.statusMessage)
  //       }
  //     }
  //   })
  // };
  // 新的注销方法 会判断是否是D53再进行注销.  此方法逻辑处理已废弃，还原之前的逻辑

  // 注销方法，还原之前的逻辑
  handleLogoutWithKey = record => {
    this.handleLogout(record.vin);
  };
  // D53车辆注销方法，已废弃
  // handleLogoutBlueTooth = (vin) =>{
  //   const { dispatch } = this.props;
  //   // 查询是否存在蓝牙钥匙
  //   dispatch({
  //     type: 'alarm/fetch',
  //     payload: { url:'/vehicle/findBlueTooth', vin },
  //     callback: response =>{
  //       if(response.statusCode === '0'){
  //         if(response.data && response.data.owner && response.data.owner.length > 0){
  //           // 存在车主钥匙，进行注销操作
  //           const data = {};
  //           data.deviceId = vin;
  //           data.bleKeyId = response.data.owner[0].id;
  //           dispatch({
  //             type: 'alarm/add',
  //             payload: { url: '/vehicle/deleteBlueTooth', ...data },
  //             callback: response=>{
  //               response.statusCode === "0" ? message.success("指令已下发，您可以查看钥匙操作日志追踪指令状态。") : message.error(response.statusMessage)
  //             }
  //           });
  //         }
  //       }
  //       //  无论蓝牙钥匙结果都调用车辆注销
  //       this.handleLogout(vin);
  //     }
  //   })
  // };

  //WindLink跳转蓝牙钥匙页面
  handleBlueToothKey = record => {
    const { dispatch } = this.props;
    const { formValues } = this.state;
    const data = { vin: record.vin, type: record.vhlType };
    const query = { pageObj: page, values: formValues };
    // 黑白名单判断
    dispatch({
      type: 'alarm/fetch',
      payload: { url: '/vehicle/checkBlueTooth', vin: record.vin },
      callback: response => {
        if (response.statusCode === '0') {
          if (response.data === true) {
            sessionStorage.setItem('blueToothData', JSON.stringify(data));
            sessionStorage.setItem('query', JSON.stringify(query));
            dispatch(
              routerRedux.push({
                pathname: '/deviceManager/blueTooth',
              }),
            );
          } else {
            message.warning('该车辆无蓝牙钥匙');
          }
        } else {
          message.error(response.statusMessage);
        }
      },
    });
  };

  //车联网跳蓝牙钥匙页面
  handleBlueToothKeyClw = record => {
    const { dispatch } = this.props;
    const { formValues } = this.state;
    const data = { vin: record.vin, type: record.vhlType };
    const query = { pageObj: page, values: formValues };
    sessionStorage.setItem('blueToothData', JSON.stringify(data));
    sessionStorage.setItem('query', JSON.stringify(query));
    dispatch(
      routerRedux.push({
        pathname: '/deviceManager/blueToothClw',
      }),
    );
  };

  renderForm() {
    const {
      dealerOptions,
      factoryOptions,
      factoryVisible,
      dealerVisible,
      typeSearchOptions,
      enrollStatusOptions,
      realNameStatusOptions,
    } = this.state;
    // const enrollStatusOptions = getDicByCodeSort(this.context.dicData, 'vehicleEnrollStatus');
    // const realNameStatusOptions = getDicByCodeSort(this.context.dicData, 'vehicleRealNameStatus');
    // const { getFieldDecorator } = this.props.form;
    const {
      qualityTest: { options },
    } = this.props; // 集团编码关系
    const GroupOption = (options || []).map(d => <Option key={d.value}>{d.label}</Option>);
    const searchItems = [
      {
        title: 'VIN号',
        type: 'input',
        key: 'vin',
      },
      {
        title: '类型',
        type: 'select',
        optionsType: 'option',
        selectOptions: typeSearchOptions,
        key: 'vhlType',
      },
      {
        title: '激活状态',
        type: 'select',
        optionsType: 'option',
        selectOptions: enrollStatusOptions,
        key: 'enrollStatus',
      },
      {
        title: '实名认证状态',
        type: 'select',
        optionsType: 'option',
        selectOptions: realNameStatusOptions,
        key: 'realNameStatus',
      },
      {
        title: '集团企业',
        type: 'select',
        optionsType: 'option',
        selectOptions: GroupOption,
        key: 'groupId',
      },
      {
        title: '车厂',
        type: 'select',
        optionsType: 'option',
        selectOptions: factoryOptions,
        onSelectChange: v => this.onFactorySelect(v),
        key: 'levelCode',
      },
      {
        title: '经销商',
        type: 'select',
        filterOption: (input, option) =>
          option.props.title.toLowerCase().indexOf(input.toLowerCase()) >= 0,
        optionsType: 'option',
        selectOptions: dealerOptions,
        key: 'dealerNo',
      },
      {
        title: '网联类型',
        type: 'select',
        optionsType: 'option',
        selectOptions: [<Option key={1}>手机</Option>, <Option key={0}>传统</Option>],
        key: 'carSpt',
      },
    ];
   
    return (
      <Card bordered={false}>
        <PateoSearchForm
        searchItems={dealerVisible? (factoryVisible? searchItems : searchItems.filter(item => item.key !== 'levelCode')) : (factoryVisible? searchItems : searchItems.filter(item => item.key !== 'levelCode')).filter(item => (item.key !== 'dealerNo')&&(item.key !== 'carSpt'))}
          // searchItems={searchItems}
          onRef={ref => (this.fromRef = ref)}
          fetchParams={{ type: 'vehicle/fetch' }}
          saveFormValues={val =>
            this.setState({ formValues: Object.assign(this.state.formValues, val) })
          }
          handleFormReset={() => this.setState({ formValues: {} })}
        />
        {/* <Row>
           <Col style={colStyle} span={24}>
             {isAuth ? (<Button icon={(<PlusOutlined />)} type="primary" size='small' onClick={() => this.props.history.push('/deviceManager/simCard/simCardAdd')}>新增</Button>) : ''}
           </Col>
         </Row> */}
      </Card>
      // <Form onFinish={this.handleSearch} layout="inline" ref="searchForm">
      //   <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
      //     <Col md={8} sm={24}>
      //       <FormItem label="VIN号" name="vin">
      //         <Input placeholder="VIN号" />
      //       </FormItem>
      //     </Col>
      //     <Col md={8} sm={24}>
      //       <FormItem label="类型" name="vhlType">
      //         <Select placeholder="请选择" getPopupContainer={triggerNode => triggerNode.parentNode}>
      //           {typeSearchOptions}
      //         </Select>
      //       </FormItem>
      //     </Col>
      //     <Col md={8} sm={24}>
      //       <FormItem label="激活状态" name="enrollStatus">
      //         <Select placeholder="请选择" getPopupContainer={triggerNode => triggerNode.parentNode}>
      //           {enrollStatusOptions}
      //         </Select>
      //       </FormItem>
      //     </Col>
      //   </Row>
      //   <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
      //     <Col md={8} sm={24}>
      //       <FormItem label="实名认证状态" name="realNameStatus">
      //         <Select placeholder="请选择" getPopupContainer={triggerNode => triggerNode.parentNode}>
      //           {realNameStatusOptions}
      //         </Select>
      //       </FormItem>
      //     </Col>
      //     <Col  md={8} sm={24}>
      //       <FormItem label="集团企业" name="groupId">
      //         <Select
      //           allowClear
      //           placeholder="请选择"
      //           showSearch
      //           optionFilterProp="children"
      //           getPopupContainer={triggerNode => triggerNode.parentNode}
      //         >
      //           { GroupOption }
      //         </Select>
      //       </FormItem>
      //     </Col>
      //     <Col style={factoryVisible} md={8} sm={24}>
      //       <FormItem label="车厂" name="levelCode">
      //         <Select placeholder="请选择" onChange={this.onFactorySelect} getPopupContainer={triggerNode => triggerNode.parentNode}>
      //           {factoryOptions}
      //         </Select>
      //       </FormItem>
      //     </Col>
      //     <Col style={dealerVisible} md={8} sm={24}>
      //       <FormItem label="经销商" name="dealerNo">
      //         <Select
      //           allowClear
      //           placeholder="请选择"
      //           showSearch
      //           getPopupContainer={triggerNode => triggerNode.parentNode}
      //           filterOption={(input, option) => option.props.title.toLowerCase().indexOf(input.toLowerCase()) >= 0}
      //         >
      //           {dealerOptions}
      //         </Select>
      //       </FormItem>
      //     </Col>
      //     <Col style={dealerVisible} md={8} sm={24}>
      //       <FormItem label="网联类型" name="carSpt">
      //         <Select placeholder="请选择" allowClear>
      //           <Option key={1}>手机</Option>
      //           <Option key={0}>传统</Option>
      //         </Select>
      //       </FormItem>
      //     </Col>
      //     {factoryVisible !== {} ? (
      //       <Col md={5} sm={24} style={{ float: 'right' }}>
      //         <Button type="primary" htmlType="submit">查询</Button>
      //         <Button style={{ marginLeft: 8 }} htmlType="reset" onClick={this.handleFormReset}>重置</Button>
      //       </Col>
      //     ) : ''}
      //   </Row>
      //   {factoryVisible === {} ? (
      //     <Row>
      //       <Col md={5} sm={24} style={{ float: 'right' }}>
      //         <Button type="primary" htmlType="submit">查询</Button>
      //         <Button style={{ marginLeft: 8 }} htmlType="reset" onClick={this.handleFormReset}>重置</Button>
      //       </Col>
      //     </Row>
      //   ) : ''}
      // </Form>
    );
  }

  render() {
    const {
      typeOptions,
      activeVisible,
      data,
      title,
      label,
      formValues,
      activeBatchVisible,
      detailDisable,
      inputVisible,
      dateVisible,
      phoneVisible,
      type,
      templateFileUrl,
      typeBatchOptions,
      activeDealerOptions,
      activeDealerVisible,
      uploadUrlVisible,
      urlsVisible,
      activeFileUrl,
      modelVisible,
      activeTypeDisabled,
      reActiveFlag,
      businessLicenseVisible,
      codeVisible,
      phoneDisable,
      qualityUserOptions,
      qualityVisible,
      declarerVisible,
      qualityUserMap,
      phoneMap,
      remarksDesc,
      realNameDisable,
      showUploadList,
      groupActiveFileUrl,
      subDealerVisible,
    } = this.state;

    const {menu: { permissions }} = this.props;
    const {location: { pathname }} = this.props;
    const isAuth = permissions.includes(pathname + '/' + 'vehicle-opt');
    const isReSend = permissions.includes(pathname + '/' + 'vehicle-send'); //重发激活消息
    const isBatch = permissions.includes(pathname + '/' + 'vehicle-batchActive');
    const isBind = permissions.includes(pathname + '/' + 'vehicle-bind'); //修改绑定关系
    const isActive = permissions.includes(pathname + '/' + 'vehicle-active'); //激活
    const isRelieve =  permissions.includes(pathname + '/' + 'vehicle-relieve');
    const isReActive =  permissions.includes(pathname + '/' + 'vehicle-reActive');
    const isRealName = false && permissions.includes(pathname + '/' + 'vehicle-realName'); //重新提交实名认证  按钮隐藏
    const isDetail = permissions.includes(pathname + '/' + 'vehicleDetail-look');
    // todo   标注为新加的button
    const groupActive =  permissions.includes(pathname + '/' + 'vehicle-groupActive');
    const untying = permissions.includes(pathname + '/' + 'vehicle-untying');
    const binding = permissions.includes(pathname + '/' + 'vehicle-binding');
    const history = permissions.includes(pathname + '/' + 'vehicle-bindHistory');
    //windlink蓝牙钥匙权限
    const blueTooth = true || this.context.authButton.includes('vehicle-blueTooth');
    //车联网蓝牙钥匙权限
    const blueToothClw = true || this.context.authButton.includes('vehicle-blueToothClw');
    const isS31 = permissions.includes(pathname + '/' + 'vehicle-forS31');


    // const isAuth = true || this.context.authButton.includes('vehicle-opt');
    // const isReSend = true || this.context.authButton.includes('vehicle-send'); //重发激活消息
    // const isBatch = true || this.context.authButton.includes('vehicle-batchActive');
    // const isBind = true || this.context.authButton.includes('vehicle-bind'); //修改绑定关系
    // const isActive = true || this.context.authButton.includes('vehicle-active'); //激活
    // const isRelieve = true || this.context.authButton.includes('vehicle-relieve');
    // const isReActive = true || this.context.authButton.includes('vehicle-reActive');
    // const isRealName = false && this.context.authButton.includes('vehicle-realName'); //重新提交实名认证  按钮隐藏
    // const isDetail = true || this.context.authButton.includes('vehicleDetail-look');
    // // todo   标注为新加的button
    // const groupActive = true || this.context.authButton.includes('vehicle-groupActive');
    // const untying = true || this.context.authButton.includes('vehicle-untying');
    // const binding = true || this.context.authButton.includes('vehicle-binding');
    // const history = true || this.context.authButton.includes('vehicle-bindHistory');
    // //windlink蓝牙钥匙权限
    // const blueTooth = true || this.context.authButton.includes('vehicle-blueTooth');
    // //车联网蓝牙钥匙权限
    // const blueToothClw = true || this.context.authButton.includes('vehicle-blueToothClw');

    const {
      vehicle: {
        loading,
        list: { list, pagination },
      },
      dispatch,
    } = this.props;
    page = pagination;

    const activeButton = record => (
      <span>
        <a onClick={() => this.handleActive(record)}>激活</a>
        <Divider type="vertical" />
      </span>
    );
    const reActiveButton = record =>
      isReActive ? (
        <span>
          <a onClick={() => this.handleReActive(record)}>重新提交审核</a>
          <Divider type="vertical" />
        </span>
      ) : (
        ''
      );
      //重新提交实名认证按钮删除
    const realNameButton = record =>
      isRealName ? (
        <span>
          <a onClick={() => this.handleReActive(record)}>重新提交实名认证</a>
          <Divider type="vertical" />
        </span>
      ) : (
        ''
      );
    const bindButton = record => (
      record.enrollStatus === 0 ?
        <span>
          <a onClick={() => this.handleBindingData(record)}>修改绑定关系</a>
          <Divider type="vertical" />
        </span> : null
    );
    const operationButton = record => (
      <span>
        <a onClick={() => this.handleEditVIN(record)}>编辑</a>
        <Divider type="vertical" />
      </span>
    );
    const groupActiveButton = record => (
      <span>
        <a onClick={() => this.handleGroupActive(record)}>集团企业批量激活</a>
      </span>
    );
    const untyingButton = record => (
      <span>
        <a onClick={() => this.handleUntying(record)}>解绑</a>
        <Divider type="vertical" />
      </span>
    );
    const bindingButton = record => (
      <span>
        <a onClick={() => this.handleBingUser(record)}>绑定</a>
        <Divider type="vertical" />
      </span>
    );
    const historyButton = record => (
      <span>
        <a onClick={() => this.handleHistory(record)}>历史记录明细</a>
        <Divider type="vertical" />
      </span>
    );
    //windLink蓝牙钥匙按钮
    const blueToothButton = record => {
      return null;
      return (
        <span>
          <a onClick={() => this.handleBlueToothKey(record)}>蓝牙钥匙</a>
          <Divider type="vertical" />
        </span>
      );
    };
    //车联网蓝牙钥匙Key按钮
    const blueToothButtonClw = record => {
      return null;
      return (
        <span>
          <a onClick={() => this.handleBlueToothKeyClw(record)}>蓝牙钥匙</a>
          <Divider type="vertical" />
        </span>
      );
    };
    const confirmDom = (confirm, title, description) => (
      <Popconfirm title={title} onConfirm={confirm}>
        <a>{description}</a>
      </Popconfirm>
    );
    //蓝牙钥匙权限判断
    const blueKeyPower = getDicByKey(this.context.dicData, 'blueKeyPower', 'blueKeyPower')
      ? getDicByKey(this.context.dicData, 'blueKeyPower', 'blueKeyPower').split(',')
      : [];
    //  蓝牙钥匙环境配置开关  若获取到此配置且为true表示使用原有逻辑
    const switchBlueKey =
      getDicByKey(this.context.dicData, 'blueKeySwitch', 'blueKeySwitch') === 'true';
    const columns = [
      {
        title: 'VIN号',
        dataIndex: 'vin',
        render: (text, record) => {
          if (isDetail) {
            return <a onClick={() => this.handleDetailVIN(record)}>{text}</a>;
          } else {
            return text;
          }
        },
      },
      {
        title: '品牌',
        dataIndex: 'brandId',
        render: text => {
          if (text) {
            return getDicByKey(this.context.dicData, 'optBrand', text) || text;
          } else {
            return text;
          }
        },
      },
      {
        title: '车系',
        dataIndex: 'seriesId',
        render: text => {
          if (text) {
            return getDataByCode(this.state.redisData, 'vehicleSeriesList', text) || text;
          } else {
            return text;
          }
        },
      },
      {
        title: '车型',
        dataIndex: 'styleId',
        render: text => {
          if (text) {
            return getDataByCode(this.state.redisData, 'vehicleTypeList', text) || text;
          } else {
            return text;
          }
        },
      },
      {
        title: '颜色',
        dataIndex: 'colorName',
      },
      {
        title: '经销商',
        dataIndex: 'dealerId',
        render: text => {
          if (text) {
            return getDataByCode(this.state.redisData, 'dealerList', text) || text;
          } else {
            return text;
          }
        },
      },
      {
        title: '网联类型',
        dataIndex: 'isClw',
        render: (text, record) => {
          if (record.carSpt && record.carSpt === '1') {
            return '手机';
          } else {
            return '传统';
          }
        },
      },
      {
        title: '集团企业',
        dataIndex: 'groupId',
        render: (text, record) => {
          if (text && record.vhlType === 7) {
            const {
              qualityTest: { options },
            } = this.props; // 集团编码关系
            const option = options.filter(item => item.value === text);
            return option.length > 0 ? option[0].label : text;
          } else return null;
        },
      },
      {
        title: '类型',
        dataIndex: 'vhlType',
        render: text => {
          if (text || text === 0) {
            return typeMap.get(text) ? typeMap.get(text) : text;
          } else {
            return text;
          }
        },
      },
      {
        title: '激活状态',
        dataIndex: 'enrollStatus',
        render: (text, record) => {
          // 如果状态码为0 并且 remark等于“等待app激活” 就显示remark的值
          if (text === 0 && record.remarks === '等待app激活') {
            return record.remarks;
          }
          // 状态码有值 并且在 enrollMap 可以查到就显示对应的值 否则 显示空
          return (text || text === 0) && enrollMap.get(text) ? enrollMap.get(text) : '';
          // if ((text === 0) && (record.remarks !== null) && (record.remarks !== '') ){
          //   return record.remarks;
          // } else {
          //   if (text || text === 0) {
          //     return enrollMap.get(text) ? enrollMap.get(text) : text;
          //   } else {
          //     return text;
          //   }
          // }
        },
      },
      {
        title: '实名认证状态',
        dataIndex: 'realNameStatus',
        render: (text, record) => {
          if (
            record.vhlType === 3 ||
            record.vhlType === 4 ||
            record.vhlType === 5 ||
            record.vhlType === 6
          ) {
            return '';
          } else {
            if (text) {
              return realMap.get(text) ? realMap.get(text) : text;
            } else {
              return text;
            }
          }
        },
      },
      {
        title: '备注',
        dataIndex: 'remarks',
        render: (text, record) => {
          if (record.enrollStatus === 5 || record.realNameStatus === '3') {
            return (
              <span style={{ color: 'red' }}>
                <Ellipsis length={10} tooltip>
                  {text}
                </Ellipsis>
              </span>
            );
          } else {
            return '';
          }
        },
      },
      {
        title: '入库时间',
        dataIndex: 'createDate',
        render: text => {
          return text;
        },
      },
      {
        title: '车机',
        dataIndex: 'pdsn',
        render: text => {
          if (detailDisable) {
            return text;
          } else {
            return <a onClick={() => this.handleDetailIPDA(text)}>{text}</a>;
          }
        },
      },
      {
        title: 'TBOX',
        dataIndex: 'tbox',
        render: text => {
          if (detailDisable) {
            return text;
          } else {
            return <a onClick={() => this.handleDetailTbox(text)}>{text}</a>;
          }
        },
      },
      {
        title: '操作',
        dataIndex: '操作',
        width: 350,
        fixed: 'right',
        render: (text, record) => {
          const isClw = record.carSpt && record.carSpt === '1'; //是否为车联网数据
          if (record.enrollStatus === 0) {
            return (
              <div>
                {(isActive === true && record.vhlType !== 1)? activeButton(record) : ''}
                {!isClw && isBind === true ? bindButton(record) : ''}
                {isAuth === true ? operationButton(record) : ''}
                {isClw
                  ? blueToothClw && blueToothButtonClw(record)
                  : blueTooth && blueToothButton(record)}
              </div>
            );
          } else if (record.enrollStatus === 1) {
            if (
              record.vhlType === 3 ||
              record.vhlType === 4 ||
              record.vhlType === 5 ||
              record.vhlType === 6 || 
              record.vhlType === 9
            ) {
              if (record.realNameStatus === '3') {
                return (
                  <div>
                    {(isRelieve && record.vhlType !== 1)// 用户车不可注销
                      ? confirmDom(() => this.handleLogoutWithKey(record), '确定要注销吗?', '注销')
                      : ''}
                    {(isRelieve === true && record.vhlType !== 1)? <Divider type="vertical" /> : ''}
                    {/* {realNameButton(record)} */}
                    {!isClw && isReSend === true
                      ? confirmDom(
                          () => this.handleReSendActiveInfo(record),
                          '确定要重发激活消息吗?',
                          '重发激活消息',
                        )
                      : ''}
                    {!isClw && isReSend === true ? <Divider type="vertical" /> : ''}
                    {!isClw && isBind === true ? bindButton(record) : ''}
                    {isAuth === true ? operationButton(record) : ''}
                    {isClw
                      ? blueToothClw && blueToothButtonClw(record)
                      : blueTooth && blueToothButton(record)}
                  </div>
                );
              } else {
                return (
                  <div>
                    {(isRelieve && record.vhlType !== 1)// 用户车不可注销
                      ? confirmDom(() => this.handleLogoutWithKey(record), '确定要注销吗?', '注销')
                      : ''}
                    {(isRelieve === true && record.vhlType !== 1)? <Divider type="vertical" /> : ''}
                    {!isClw && isReSend === true
                      ? confirmDom(
                          () => this.handleReSendActiveInfo(record),
                          '确定要重发激活消息吗?',
                          '重发激活消息',
                        )
                      : ''}
                    {!isClw && isReSend === true ? <Divider type="vertical" /> : ''}
                    {!isClw && isBind === true ? bindButton(record) : ''}
                    {isAuth === true ? operationButton(record) : ''}
                    {isClw
                      ? blueToothClw && blueToothButtonClw(record)
                      : blueTooth && blueToothButton(record)}
                  </div>
                );
              }
            } else if (record.vhlType === 1 || record.vhlType === 2) {
              const {menu: { userProfile , dataPermission}} = this.props;
              // if (orgType) {
                if (dataPermission.PERSON && dataPermission.PERSON.length > 0 && dataPermission.PERSON[0] == '1') {//运维
              // const { levelCode } = this.props.currentUser;
              // if (levelCode) {
              //   if (levelCode.split('-').length === 2) {
                  if (record.realNameStatus === '3') {
                    return (
                      <div>
                        {(isRelieve && record.vhlType !== 1)// 用户车不可注销
                          ? confirmDom(
                              () => this.handleLogoutWithKey(record),
                              this.getMessage(record.vhlType),
                              '注销',
                            )
                          : ''}
                        {(isRelieve === true && record.vhlType !== 1)? <Divider type="vertical" /> : ''}
                        {/* {realNameButton(record)} */}
                        {!isClw && isReSend === true
                          ? confirmDom(
                              () => this.handleReSendActiveInfo(record),
                              '确定要重发激活消息吗?',
                              '重发激活消息',
                            )
                          : ''}
                        {!isClw && isReSend === true ? <Divider type="vertical" /> : ''}
                        {!isClw && isBind === true ? bindButton(record) : ''}
                        {isAuth === true ? operationButton(record) : ''}
                        {isClw
                          ? blueToothClw && blueToothButtonClw(record)
                          : blueTooth && blueToothButton(record)}
                      </div>
                    );
                  } else {
                    return (
                      <div>
                        {(isRelieve && record.vhlType !== 1)// 用户车不可注销
                          ? confirmDom(
                              () => this.handleLogoutWithKey(record),
                              this.getMessage(record.vhlType),
                              '注销',
                            )
                          : ''}
                        {(isRelieve === true && record.vhlType !== 1)? <Divider type="vertical" /> : ''}
                        {!isClw && isReSend === true
                          ? confirmDom(
                              () => this.handleReSendActiveInfo(record),
                              '确定要重发激活消息吗?',
                              '重发激活消息',
                            )
                          : ''}
                        {!isClw && isReSend === true ? <Divider type="vertical" /> : ''}
                        {!isClw && isBind === true ? bindButton(record) : ''}
                        {isAuth === true ? operationButton(record) : ''}
                        {isClw
                          ? blueToothClw && blueToothButtonClw(record)
                          : blueTooth && blueToothButton(record)}
                      </div>
                    );
                  }
                } else {
                  if (record.realNameStatus === '3') {
                    return (
                      <div>
                        {/* {realNameButton(record)} */}
                        {!isClw && isReSend === true
                          ? confirmDom(
                              () => this.handleReSendActiveInfo(record),
                              '确定要重发激活消息吗?',
                              '重发激活消息',
                            )
                          : ''}
                        {!isClw && isReSend === true ? <Divider type="vertical" /> : ''}
                        {!isClw && isBind === true ? bindButton(record) : ''}
                        {isAuth === true ? operationButton(record) : ''}
                        {isClw
                          ? blueToothClw && blueToothButtonClw(record)
                          : blueTooth && blueToothButton(record)}
                      </div>
                    );
                  } else {
                    return (
                      <div>
                        {!isClw && isReSend === true
                          ? confirmDom(
                              () => this.handleReSendActiveInfo(record),
                              '确定要重发激活消息吗?',
                              '重发激活消息',
                            )
                          : ''}
                        {!isClw && isReSend === true ? <Divider type="vertical" /> : ''}
                        {!isClw && isBind === true ? bindButton(record) : ''}
                        {isAuth === true ? operationButton(record) : ''}
                        {isClw
                          ? blueToothClw && blueToothButtonClw(record)
                          : blueTooth && blueToothButton(record)}
                      </div>
                    );
                  }
                }
              // }
            } else if (record.vhlType === 7) {
              if (record.realNameStatus === '2')
                return (
                  <div>
                    {!isClw && isBind === true ? bindButton(record) : ''}
                    {isAuth === true ? operationButton(record) : ''}
                    {untying === true
                      ? confirmDom(() => this.handleUntying(record), '确定要解绑吗?', '解绑')
                      : ''}
                    {untying === true ? <Divider type="vertical" /> : ''}
                    {/* {history === true ? historyButton(record) : ''} */}
                    {isClw
                      ? blueToothClw && blueToothButtonClw(record)
                      : blueTooth && blueToothButton(record)}
                  </div>
                );
              else if (
                record.realNameStatus === '0' ||
                record.realNameStatus === '3' ||
                record.realNameStatus === '5'
              )
                return (
                  <div>
                    {!isClw && isBind === true ? bindButton(record) : ''}
                    {isAuth === true ? operationButton(record) : ''}
                    {/* {binding === true ? bindingButton(record) : ''} */}
                    {/* {history === true ? historyButton(record) : ''} */}
                    {isRelieve
                      ? confirmDom(() => this.handleLogoutWithKey(record), '确定要注销吗?', '注销')
                      : ''}
                    {isRelieve === true ? <Divider type="vertical" /> : ''}
                    {isClw
                      ? blueToothClw && blueToothButtonClw(record)
                      : blueTooth && blueToothButton(record)}
                  </div>
                );
              else
                return (
                  <div>
                    {!isClw && isBind === true ? bindButton(record) : ''}
                    {isAuth === true ? operationButton(record) : ''}
                    {/* {history === true ? historyButton(record) : ''} */}
                    {isClw
                      ? blueToothClw && blueToothButtonClw(record)
                      : blueTooth && blueToothButton(record)}
                  </div>
                );
            } else {
              return (
                <div>
                  {!isClw && isReSend === true
                    ? confirmDom(
                        () => this.handleReSendActiveInfo(record),
                        '确定要重发激活消息吗?',
                        '重发激活消息',
                      )
                    : ''}
                  {!isClw && isReSend === true ? <Divider type="vertical" /> : ''}
                  {!isClw && isBind === true ? bindButton(record) : ''}
                  {isAuth === true ? operationButton(record) : ''}
                  {isClw
                    ? blueToothClw && blueToothButtonClw(record)
                    : blueTooth && blueToothButton(record)}
                </div>
              );
            }
          } else if (record.enrollStatus === 2) {
            return (
              <div>
                {confirmDom(
                  () => this.handleActive(record),
                  // () => this.handleResendActive(record.vin, 2),
                  '确定要重新激活吗?',
                  '重新激活',
                )}
                <Divider type="vertical" />
                {!isClw && isBind === true ? bindButton(record) : ''}
                {isAuth === true ? operationButton(record) : ''}
                {isClw
                  ? blueToothClw && blueToothButtonClw(record)
                  : blueTooth && blueToothButton(record)}
              </div>
            );
          } else if (record.enrollStatus === 3) {
            return (
              <div>
                {confirmDom(
                 () =>  this.handleLogoutWithKey(record),
                  // () => this.handleResendActive(record.vin, 3),
                  '确定要重新注销吗?',
                  '重新注销',
                )}
                <Divider type="vertical" />
                {!isClw && isBind === true ? bindButton(record) : ''}
                {isAuth === true ? operationButton(record) : ''}
                {isClw
                  ? blueToothClw && blueToothButtonClw(record)
                  : blueTooth && blueToothButton(record)}
              </div>
            );
          } else if (record.enrollStatus === 4) {
            return (
              <div>
                {!isClw && isBind === true ? bindButton(record) : ''}
                {isAuth === true ? operationButton(record) : ''}
                {isClw
                  ? blueToothClw && blueToothButtonClw(record)
                  : blueTooth && blueToothButton(record)}
              </div>
            );
          } else if (record.enrollStatus === 5) {
            return (
              <div>
                {isBatch === true ? reActiveButton(record) : ''}
                {!isClw && isBind === true ? bindButton(record) : ''}
                {isAuth === true ? operationButton(record) : ''}
                {isClw
                  ? blueToothClw && blueToothButtonClw(record)
                  : blueTooth && blueToothButton(record)}
              </div>
            );
          } else if (record.enrollStatus === 6) {
            if (record.realNameStatus === '3') {
              return (
                <div>
                  {/* {isBatch === true ? realNameButton(record) : ''} */}
                  {!isClw && isBind === true ? bindButton(record) : ''}
                  {isAuth === true ? operationButton(record) : ''}
                  {isClw
                    ? blueToothClw && blueToothButtonClw(record)
                    : blueTooth && blueToothButton(record)}
                </div>
              );
            } else {
              return (
                <div>
                  {!isClw && isBind === true ? bindButton(record) : ''}
                  {isAuth === true ? operationButton(record) : ''}
                  {isClw
                    ? blueToothClw && blueToothButtonClw(record)
                    : blueTooth && blueToothButton(record)}
                </div>
              );
            }
          } else if (record.enrollStatus === 7) {
            if (record.realNameStatus === '3') {
              return (
                <div>
                  {/* {isBatch === true ? realNameButton(record) : ''} */}
                  {isBatch === true
                    ? confirmDom(
                        () => this.handleResendActive(record.vin, 7),
                        '确定要重新下发配置吗?',
                        '重新下发配置',
                      )
                    : ''}
                  {/* <Divider type="vertical" /> */}
                  {!isClw && isBind === true ? bindButton(record) : ''}
                  {isAuth === true ? operationButton(record) : ''}
                  {isClw
                    ? blueToothClw && blueToothButtonClw(record)
                    : blueTooth && blueToothButton(record)}
                </div>
              );
            } else {
              return (
                <div>
                  {isBatch === true
                    ? confirmDom(
                        () => this.handleResendActive(record.vin, 7),
                        '确定要重新下发配置吗?',
                        '重新下发配置',
                      )
                    : ''}
                  {/* <Divider type="vertical" /> */}
                  {!isClw && isBind === true ? bindButton(record) : ''}
                  {isAuth === true ? operationButton(record) : ''}
                  {isClw
                    ? blueToothClw && blueToothButtonClw(record)
                    : blueTooth && blueToothButton(record)}
                </div>
              );
            }
          } else if (record.enrollStatus === 9) {
            return (
              <div>
                {isBatch === true
                  ? confirmDom(
                      () => this.handleResendActive(record.vin, 9),
                      '确定要重新下发配置吗?',
                      '重新下发配置',
                    )
                  : ''}
                {/* <Divider type="vertical" /> */}
                {!isClw && isBind === true ? bindButton(record) : ''}
                {isAuth === true ? operationButton(record) : ''}
                {isClw
                  ? blueToothClw && blueToothButtonClw(record)
                  : blueTooth && blueToothButton(record)}
              </div>
            );
          } else {
            return (
              <div>
                {!isClw && isBind === true ? bindButton(record) : ''}
                {isAuth === true ? operationButton(record) : ''}
                {isClw
                  ? blueToothClw && blueToothButtonClw(record)
                  : blueTooth && blueToothButton(record)}
              </div>
            );
          }
        },
      },
    ];

    const paginationProps = {
      showSizeChanger: true,
      showQuickJumper: true,
      ...pagination,
      showTotal: () => (
        <span>共&nbsp;{pagination === undefined ? 0 : pagination.total}&nbsp;条</span>
      ),
    };
    const tableProps = {
      columns, // 列
      rowKey: record => record.sid, // key
      loading, // 控制加载
      // bordered: true, // 边框
      dataSource: list, // 远程数据
      pagination: paginationProps, // 分页
      scroll: { x: true },
    };
    return (
      <PageHeaderLayout>
        {/* <Card bordered={false}> */}
        <div className={styles.tableList}>
          <div className={styles.tableListForm}>{this.renderForm()}</div>
          <Card style={{ marginTop: 12 }}>
            <div className={styles.tableListOperator}>
              {isAuth ? (
                <Button
                  icon={<PlusOutlined />}
                  type="primary"
                  size="small"
                  onClick={() => this.props.history.push('/deviceManager/vehicle/vehicleAdd')}
                >
                  新增
                </Button>
              ) : (
                ''
              )}
              {isBatch ? (
                <Button type="primary" size="small" onClick={this.handleBatchActive}>
                  批量激活
                </Button>
              ) : (
                ''
              )}
              {groupActive ? (
                <Button type="primary" size="small" onClick={this.handleGroupActive}>
                  企业集团批量激活
                </Button>
              ) : (
                ''
              )}
              {/*{(<Button type="primary" onClick={this.handleHistory}>历史</Button>)}*/}
              {/*{(<Button type="primary" onClick={this.handleBingUser}>绑定</Button>)}*/}
              {/*{(<Button type="primary" onClick={this.handleUntying}>解绑</Button>)}*/}
            </div>
            <PateoTable
              tableProps={tableProps}
              dispatch={dispatch}
              fetchParams={{ type: 'vehicle/fetch' }}
              formValues={this.state.formValues}
            />
          </Card>
          <TboxDetailModal
            changeVisible={() =>
              this.setState({ tboxDetailVisible: false, tboxDetailModelData: {} })
            }
            visible={this.state.tboxDetailVisible}
            detailModelData={this.state.tboxDetailModelData}
            dispatch={dispatch}
          />
          {/*<SIMDetailModal*/}
          {/*  changeVisible={() =>*/}
          {/*    this.setState({ simDetailVisible: false, simDetailModelData: {} })}*/}
          {/*  visible={this.state.simDetailVisible}*/}
          {/*  detailModelData={this.state.simDetailModelData}*/}
          {/*  dispatch={dispatch}*/}
          {/*/>*/}
          <IPDADetailModal
            changeVisible={() =>
              this.setState({ ipdaDetailVisible: false, ipdaDetailModelData: {} })
            }
            visible={this.state.ipdaDetailVisible}
            detailModelData={this.state.ipdaDetailModelData}
            dispatch={dispatch}
          />
          {/*<VehicleDetailModal*/}
          {/*  changeVisible={() =>*/}
          {/*    this.setState({ vinDetailVisible: false, vinDetailModelData: {} })}*/}
          {/*  visible={this.state.vinDetailVisible}*/}
          {/*  detailModelData={this.state.vinDetailModelData}*/}
          {/*  dispatch={dispatch}*/}
          {/*/>*/}
          <VehicleBindingModel
            ref="VehicleBindingModelRef"
            title="修改绑定关系"
            dispatch={dispatch}
          />
          <VehicleActiveModal
            onRef={this.onRef}
            //ref="VehicleActiveModalRef"
            typeOptions={typeOptions}
            activeVisible={activeVisible}
            handleCloseActive={this.handleCloseActive}
            dispatch={dispatch}
            data={data}
            handleSetData={this.handleSetData}
            title={title}
            label={label}
            handelSelect={this.handelSelect}
            page={page}
            formValues={formValues}
            inputVisible={inputVisible}
            phoneVisible={phoneVisible}
            type={type}
            dateVisible={dateVisible}
            activeDealerOptions={activeDealerOptions}
            activeDealerVisible={activeDealerVisible}
            uploadUrlVisible={uploadUrlVisible}
            urlsVisible={urlsVisible}
            activeFileUrl={activeFileUrl}
            modelVisible={modelVisible}
            activeTypeDisabled={activeTypeDisabled}
            reActiveFlag={reActiveFlag}
            businessLicenseVisible={businessLicenseVisible}
            codeVisible={codeVisible}
            setCodeVisible={this.setCodeVisible}
            phoneDisable={phoneDisable}
            qualityUserOptions={qualityUserOptions}
            qualityVisible={qualityVisible}
            declarerVisible={declarerVisible}
            qualityUserMap={qualityUserMap}
            phoneMap={phoneMap}
            remarksDesc={remarksDesc}
            realNameDisable={realNameDisable}
            showUploadList={showUploadList}
            subDealerVisible={subDealerVisible}
            currentUser={this.props.currentUser}
          />
          <VehicleBatchActiveModal
            onRef={this.onBatchRef}
            //ref="VehicleBatchActiveModalRef"
            typeBatchOptions={typeBatchOptions}
            activeBatchVisible={activeBatchVisible}
            handleCloseBatchActive={this.handleCloseBatchActive}
            dispatch={dispatch}
            label={label}
            page={page}
            formValues={formValues}
            templateFileUrl={templateFileUrl}
            qualityUserOptions={qualityUserOptions}
            qualityUserMap={qualityUserMap}
            phoneMap={phoneMap}
            currentUser={this.props.currentUser}
          />
          <GroupActiveModal
            onRef={this.onGroupRef}
            //typeBatchOptions={typeBatchOptions}
            groupActiveVisible={this.state.groupActiveVisible}
            handleClose={this.handleGroupClose}
            dispatch={dispatch}
            page={page}
            formValues={formValues}
            groupActiveFileUrl={this.state.groupActiveFileUrl}
            phoneMap={phoneMap}
            currentUser={this.props.currentUser}
          />
          {/*<BindUserModal*/}
          {/*  visible={this.state.bindUserVisible}*/}
          {/*  handleClose={this.handleBingUserClose}*/}
          {/*  dispatch={dispatch}*/}
          {/*  formValues={formValues}*/}
          {/*  bindData={this.state.bindData}*/}
          {/*/>*/}
          {/*<BindDetailModal*/}
          {/*  changeVisible={() =>*/}
          {/*     this.setState({ historyVisible: false, historyModalData: []})}*/}
          {/*  visible={this.state.historyVisible}*/}
          {/*  detailData={this.state.historyModalData}*/}
          {/*  dispatch={dispatch}*/}
          {/*/>*/}
        </div>
        {/* </Card> */}
      </PageHeaderLayout>
    );
  }
}

export default connect(state => {
  return {
    vehicle: state.vehicle,
    currentUser: state.user2.currentUser,
    qualityTest: state.qualityTest,
    extendForm: state.extendForm,
    menu: state.menu,
    vehicleInfo: state.vehicleInfo,
  };
})(VehicleList);
